home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGNG_C / TC_DBF.LZH / DBSTAT.C < prev    next >
Text File  |  1987-06-18  |  2KB  |  82 lines

  1. /* 
  2. **        file:        dbstat.c
  3. **        purpose:    program to list structure and statistics of dbase files
  4. **        usage:    dbstat filename
  5. **        author:    Mark Sadler
  6. **        revised:    6/18/87
  7. */
  8.  
  9.  
  10. #include <stdio.h>
  11. #include <alloc.h>
  12. #include <string.h>
  13. #include "dbf.h"
  14.  
  15.  
  16. main(int argc,char *argv[])
  17. {
  18.     int errornum;
  19.     int i,j;
  20.     struct DBF *d;
  21.     struct FIELD_RECORD *f;
  22. /* 
  23. **        if wsetargv (compuserve, bor-100, dl11) is linked in, this program will
  24. **        accept wild cards in the command line
  25. */ 
  26.     if(argc < 2)
  27.         {
  28.         printf("Usage DBSTAT filename\n");
  29.         exit(1);
  30.         }
  31.  
  32.     d = (struct DBF *)malloc(sizeof(struct DBF));        /* allocate space for DBF */
  33.  
  34.     for(j=1;j<argc;j++)
  35.     {
  36.         strcpy(d->filename,argv[j]);
  37.         if(!strchr(d->filename,'.'))            /* default to .dbf file     */
  38.             strcat(d->filename,".DBF");
  39.         if((errornum = d_open(d))!=0)            /* open file                            */
  40.         {
  41.             printf("Error opening file: ");
  42.             switch (errornum)
  43.             {
  44.                 case OUT_OF_MEM:
  45.                     printf("Not enough memory.\n");
  46.                     break;
  47.                 case NO_FILE:
  48.                     printf("Can not open file %s.\n",d->filename);
  49.                     break;
  50.                 case BAD_FORMAT:
  51.                     printf("File %s is not a dBASE III file.\n",d->filename);
  52.                     break;
  53.             }
  54.             continue;
  55.         }
  56.  
  57.         /* report stats */
  58.         printf("\nFilename:          %s\n",d->filename);
  59.         printf("Header length:     %-u\n",d->header_length);
  60.         printf("Number of fields:  %-u\n",d->num_fields);
  61.         if(d->dbf_version == DB3FILE)
  62.             printf("Version:           dBASE III\n");
  63.         else
  64.             printf("Version:           dBASE III with Memo file\n");
  65.         printf("Updated:           %02u/%02u/%2u\n",d->update_mo,d->update_day,d->update_yr);
  66.         printf("Number of records: %-u\n",d->records);
  67.         printf("Record length:     %-u\n",d->record_length);
  68.  
  69.         f = d->fields_ptr;
  70.         printf("\n\n        FILE STRUCTURE\n");
  71.         printf("\n  # FIELD NAME TYPE  LEN   DEC");
  72.         printf("\n--------------------------------\n");
  73.         for(i=1;i<=d->num_fields;++i,f++)
  74.             printf("%3u %-12s %c  %3u   %3u\n",i,f->name,f->typ,f->len,f->dec);
  75.         printf("\f");
  76.         d_close(d);
  77.     }
  78.     free(d);
  79.     exit(0);
  80. }
  81.  
  82.